home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
tex
/
cawf404.zip
/
nreq.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-07
|
21KB
|
974 lines
/*
* nreq.c - cawf(1) processing of nroff requests
*/
/*
* Copyright (c) 1991 Purdue University Research Foundation,
* West Lafayette, Indiana 47907. All rights reserved.
*
* Written by Victor A. Abell <abe@mace.cc.purdue.edu>, Purdue
* University Computing Center. Not derived from licensed software;
* derived from awf(1) by Henry Spencer of the University of Toronto.
*
* Permission is granted to anyone to use this software for any
* purpose on any computer system, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The author is not responsible for any consequences of use of
* this software, even if they arise from flaws in it.
*
* 2. The origin of this software must not be misrepresented, either
* by explicit claim or by omission. Credits must appear in the
* documentation.
*
* 3. Altered versions must be plainly marked as such, and must not
* be misrepresented as being the original software. Credits must
* appear in the documentation.
*
* 4. This notice may not be removed or altered.
*/
#include "cawf.h"
#include <ctype.h>
/*
* Prototypes for request processing functions.
*/
_PROTOTYPE(static void nr_UL,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_Ub,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_Uc,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_Uf,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_Ur,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_ad,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_bp,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_br,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_ce,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_di,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_ds,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_fi,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_fl,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_ft,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_it,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_na,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_nf,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_ns,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_rm,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_rn,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_rr,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_rs,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_tl,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_tm,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_tr,(unsigned char *line, int brk));
_PROTOTYPE(static void nr_nil,(unsigned char *line, int brk));
/*
* NrReqt[] - nroff request processing table
*
* CAUTION: place new entries in their proper alphabetical order, since
* this table is processed with a binary search.
*/
static struct nr_req {
char *nm; /* nroff request */
void (*fun)(); /* processing function */
} NrReqt[] = {
{ "\\\"", nr_nil }, /* backslash-quote */
{ "^#", nr_UL },
{ "^=", nr_UL },
{ "^b", nr_Ub },
{ "^c", nr_Uc },
{ "^d", nr_nil },
{ "^e", nr_nil },
{ "^f", nr_Uf },
{ "^r", nr_Ur },
{ "^x", nr_nil },
{ "ad", nr_ad },
{ "bp", nr_bp },
{ "br", nr_br },
{ "ce", nr_ce },
{ "di", nr_di },
{ "ds", nr_ds },
{ "fi", nr_fi },
{ "fl", nr_fl },
{ "ft", nr_ft },
{ "i0", nr_nil },
{ "it", nr_it },
{ "lg", nr_nil },
{ "li", nr_nil },
{ "na", nr_na },
{ "nf", nr_nf },
{ "ns", nr_ns },
{ "ps", nr_nil },
{ "rm", nr_rm },
{ "rn", nr_rn },
{ "rr", nr_rr },
{ "rs", nr_rs },
{ "tl", nr_tl },
{ "tm", nr_tm },
{ "tr", nr_tr },
{ "vs", nr_nil },
};
/*
* Nreq(line, brk) - process miscellaneous nroff requests from line
* buffer with request status of (brk)
*/
void
Nreq(line, brk)
unsigned char *line;
int brk;
{
unsigned char c[3]; /* command buffer */
int cmp, hi, low, mid; /* binary search indixes */
c[0] = c[1] = c[2] = '\0';
if ((c[0] = line[1]) != '\0')
c[1] = line[2];
low = mid = 0;
hi = (sizeof(NrReqt) / sizeof(struct nr_req)) - 1;
while (low <= hi) {
mid = (low + hi) / 2;
if ((cmp = strcmp((char *)c, NrReqt[mid].nm)) < 0)
hi = mid - 1;
else if (cmp > 0)
low = mid + 1;
else {
(void) (*NrReqt[mid].fun)(line, brk);
return;
}
}
/*
* Unknown request starting with a '.' or '\''..
*/
Error(WARN, LINE, " unknown request", NULL);
}
/*
* Adjust - "^[.']ad"
*/
static void
nr_ad(line, brk)
unsigned char *line;
int brk;
{
Pass3(NOBREAK, (unsigned char *)"both", -1, NULL, 0);
}
/*
* Begin new page - "^[.']bp"
*/
static void
nr_bp(line, brk)
unsigned char *line;
int brk;
{
Pass3(brk, (unsigned char *)"need", -1, NULL, 999);
}
/*
* Break - "^[.']br"
*/
static void
nr_br(line, brk)
unsigned char *line;
int brk;
{
Pass3(brk, (unsigned char *)"flush", -1, NULL, 0);
}
/*
* Center - "^[.']ce"
*/
static void
nr_ce(line, brk)
unsigned char *line;
int brk;
{
unsigned char *s; /* string poiner */
if ((s = Field(2, line, 0)) != NULL)
Centering = atoi((char *)s);
else
Centering = 1;
}
/*
* Diversion on and off - "^[.']di"
*/
static void
nr_di(line, brk)
unsigned char *line;
int brk;
{
Pass3(DOBREAK, (unsigned char *)"flush", -1, NULL, 0);
Divert ^= 1;
}
/*
* Define string - "^[.']ds"
*/
static void
nr_ds(line, brk)
unsigned char *line;
int brk;
{
unsigned char buf[MAXLINE]; /* temporary buffer */
unsigned char nm[4], nm1[4]; /* name buffers */
unsigned char *s1, *s2, *s3, /* temporary string pointers */
*s4, *s5;
if (Asmname(&line[3], nm) == 0) {
Error(WARN, LINE, " no name", NULL);
return;
}
if ((s4 = Field(3, line, 0)) == NULL)
s4 = (unsigned char *)"";
/*
* Convert "\\b" to '\b' and "\\\\" to '\\'. Pass all other sequences,
* beginning with '\\', unmodified.
*/
s1 = buf;
while ((s5 = (unsigned char *)strchr((char *)s4, '\\')) != NULL) {
while (s5 > s4)
*s1++ = *s4++;
s4 = ++s5;
if (*s5 == '\\')
*s1++ = '\\';
else if (*s5 == 'b')
*s1++ = '\b';
else {
*s1++ = '\\';
*s1++ = *s5;
}
if (*s4)
s4++;
}
while (*s1++ = *s4++)
;
/*
* Install the string and see if it's an indirect reference -- e.g.,
*
* .ds S1 \*(S2
*/
s2 = Findstr(nm, buf, 1);
while (*s2 == '\\' && *(s2 + 1) == '*') {
s2++;
s3 = Asmcode(&s2, nm1);
s2 = Findstr(nm1, NULL, 0);
}
if (Hdft) {
/*
* Look for names LH, LF, CH, CF, RH, RF.
*/
if ((nm[0]=='L' || nm[0]=='C' || nm[0]=='R')
&& (nm[1]=='F' || nm[1]=='H')) {
(void) sprintf((char *)buf, "%s", (char *)nm);
Pass3(NOBREAK, buf, -1, s2, 0);
}
}
}
/*
* Fill - "^[.']fi"
*/
static void
nr_fi(line, brk)
unsigned char *line;
int brk;
{
Fill = 1;
Pass3(brk, (unsigned char *)"flush", -1, NULL, 0);
}
/*
* Flush - "^[.']fl"
*/
static void
nr_fl(line, brk)
unsigned char *line;
int brk;
{
Pass3(brk, (unsigned char *)"flush", -1, NULL, 0);
}
/*
* Font - "^[.']ft <font_name>"
*/
static void
nr_ft(line, brk)
unsigned char *line;
int brk;
{
int i; /* temporary index */
if (line[3] == '\0' || line[4] == '\0')
line[4] = 'P';
if (line[4] == 'P') {
Font[0] = Prevfont;
return;
}
for (i = 0; Fcode[i].nm; i++) {
if (Fcode[i].nm == line[4])
break;
}
if (Fcode[i].status == '\0') {
Error(WARN, LINE, " bad font code", NULL);
return;
}
Prevfont = Font[0];
Font[0] = line[4];
}
/*
* Input trap - "^[.']it [1 <request>]"
*/
static void
nr_it(line, brk)
unsigned char *line;
int brk;
{
unsigned char buf[MAXLINE]; /* temporary buffer */
int i; /* temporary index */
unsigned char *s1, *s2; /* temporary string pointers */
if ((s1 = Field(2, line, 0))